<#include "admin/common/include/sysparam.html">
<script type="text/javascript">
	function uploadNavPic() {
		ajax.upload({
			fileEleId : 'upfile1',
			filePathId : 'imageUrl',
			successFn : function(data) {
				var isImg = /\.(gif|jpg|jpeg|png|GIF|JPG|PNG)$/
						.test(data.result.webfilePath);
				if (isImg)
					$('#imgShow').attr("src", data.result.webfilePath);
			}
		})

	}
</script>

<div id="navModel" class="modal hide fade" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-header green">

		<button type="button" class="close" data-dismiss="modal"
			aria-hidden="true"></button>
		<h4 id="myModalLabel">
			<strong>导航栏编辑</strong>
		</h4>
	</div>
	<div class="alert alert-error " id="errtip" style="display: none;"></div>

	<div class="modal-body" style="max-height: 550px;">
		<!-- BEGIN FORM-->
		<form action="${contextPath}/Admin-Nav-save.action" id="navAddForm"
			class="form-horizontal" method="post">
			<input type="hidden" name="id" value="${(bean.id)?if_exists}" />
			<script>
				var zTree;
				var demoIframe;
				function removeHoverDom(treeId, treeNode) {
					$("#addBtn_" + treeNode.tId).unbind().remove();
					$("#removeBtn_" + treeNode.tId).unbind().remove();
					$("#editBtn_" + treeNode.tId).unbind().remove();
				};

				var setting = {
					check : {
						enable : true
					},
					view : {
						//addHoverDom : addHoverDom,
						removeHoverDom : removeHoverDom,
						dblClickExpand : false,
						showLine : false,
						selectedMulti : false
					},
					data : {
						simpleData : {
							enable : true,
							idKey : "id",
							pIdKey : "pId",
							rootPId : ""
						}
					},
					callback : {
						beforeClick : function(treeId, treeNode) {
							var zTree = $.fn.zTree.getZTreeObj("tree");
							if (treeNode.isParent) {
								zTree.expandNode(treeNode);
								return false;
							} else {
								demoIframe.attr("src", treeNode.file + ".html");
								return true;
							}
						},
						onClick : function(event, treeId, treeNode) { 
							$('#selectCategoryId').val(treeNode.id);
							$('#selectCategoryName').val(treeNode.name);
						}
					}

				};

				$(document).ready(function() {
					initTree();
				});

				function initTree() {
					var t = $("#tree");
					var categoryTreeJson;
					ajax
							.syncJsonRequest({
								url : '${contextPath}/Admin-ResCategory-queryCatagoryTree.action',
								success : function(data) {
									categoryTreeJson = data.result;
								}
							});
					t = $.fn.zTree.init(t, setting, categoryTreeJson);
					demoIframe = $("#testIframe");
					demoIframe.bind("load", loadReady);
					var zTree = $.fn.zTree.getZTreeObj("tree");
					zTree.selectNode(zTree.getNodeByParam("id", 101));
				}

				function loadReady() {
					var bodyH = demoIframe.contents().find("body").get(0).scrollHeight, htmlH = demoIframe
							.contents().find("html").get(0).scrollHeight, maxH = Math
							.max(bodyH, htmlH), minH = Math.min(bodyH, htmlH), h = demoIframe
							.height() >= maxH ? minH : maxH;
					if (h < 530)
						h = 530;
					demoIframe.height(h);
				}
			</script>
			<div class="control-group">
				<label class="control-label">资源分类<span class="required">*</span></label>
				<div class="controls">
					<ul id="tree" class="ztree" style="width: 300px; overflow: auto;"></ul>
				</div>
			</div>

			<div class="control-group">
				<label class="control-label">已选分类<span class="required">*</span></label>
				<div class="controls">
					<input type="hidden" name="selectCategoryId" id="selectCategoryId" />
					<input type="text" name="selectCategoryName"
						id="selectCategoryName" require="true" datatype="require"
						msg="分类不能为空" class="span2 m-wrap" readonly="readonly" />
				</div>
			</div>


			<div class="modal-footer">
				<button type="button" id="selectCategory_btn" class="btn blue">选择</button>
				<button class="btn " data-dismiss="modal" aria-hidden="true">关闭</button>
			</div>
		</form>
		<!-- END FORM-->
	</div>
</div>

<script>
	jQuery(document).ready(function() {
	 
		$("#tree").find('span').each(function(){
			 if($(this).hasClass('ico_docu') ) {
				 $(this).removeClass("button");
				 $(this).removeClass("ico_docu");
			 } 
			 if($(this).hasClass('ico_open') ) {
				 $(this).removeClass("button");
				 $(this).removeClass("ico_open");
			 } 
			 
		});
		$("#selectCategory_btn").bind("click", function() { 
			var categoryName = '${categoryName}';
			var categoryId = '${categoryId}';
			$('#'+categoryId).val($('#selectCategoryId').val());
			$('#'+categoryName).val($('#selectCategoryName').val());
			$('#navModel').modal('hide');
		});
		
	});
</script>